﻿using System;
using System.Collections.Generic;

namespace TestMonkey.Models
{
	/// <summary>
	/// This object is passed as the Model property to each template.
	/// </summary>
	public class ModelRoot
	{
		readonly Setup m_Setup;
		readonly Type m_Type;
		readonly TestModel m_Test;
		readonly ClassModel m_Class;

		/// <summary>
		/// Initializes a new instance of the <see cref="ModelRoot"/> class.
		/// </summary>
		/// <param name="setup">The setup.</param>
		/// <param name="type">The type.</param>
		/// <exception cref="System.ArgumentNullException">
		/// setup;setup is null.
		/// or
		/// type;type is null.
		/// </exception>
		public ModelRoot(Setup setup, Type type)
		{
			if (setup == null)
				throw new ArgumentNullException("setup", "setup is null.");
			if (type == null)
				throw new ArgumentNullException("type", "type is null.");

			m_Setup = setup;
			m_Type = type;
			m_Test = new TestModel(setup, type);
			m_Class = new ClassModel(setup, type);
		}

		/// <summary>
		/// Gets the test runner.
		/// </summary>
		/// <value>
		/// The test runner.
		/// </value>
		public TestRunners.TestRunner TestRunner
		{
			get { return m_Setup.TestRunner; }
		}

		/// <summary>
		/// Gets the model for the test being constructed.
		/// </summary>
		/// <value>
		/// The test.
		/// </value>
		public TestModel Test
		{
			get { return m_Test; }
		}

		/// <summary>
		/// Gets the class the test describes.
		/// </summary>
		/// <value>
		/// The class.
		/// </value>
		public ClassModel Class
		{
			get { return m_Class; }
		}

		/// <summary>
		/// Gets the setup for the test generator.
		/// </summary>
		/// <value>
		/// The setup.
		/// </value>
		public Setup Setup
		{
			get { return m_Setup; }
		}

		/// <summary>
		/// Gets the type thr class describes.
		/// </summary>
		/// <value>
		/// The type.
		/// </value>
		public Type Type
		{
			get { return m_Type; }
		}

		/// <summary>
		/// Gets the tag attributes for the class level.
		/// </summary>
		/// <value>
		/// The tag attributes.
		/// </value>
		public CodeString TagAttributes
		{
			get
			{
				if (m_Setup.UseTags)
				{
					var tags = new List<string>();
					tags.AddRange(m_Setup.CustomTags);
					tags.Add(Class.SafeName);
					tags.Add(Class.Namespace);
					tags.Add(Class.FullName);
					return TestRunner.TagAttributes(tags);
				}
				return "";
			}
		}




	}
}